import urllib.parse as up
import urllib.request as ur
'''
https://tieba.baidu.com/f?kw=%E8%8B%B1%E9%9B%84%E8%81%94%E7%9B%9F&ie=utf-8&pn=50
'''
kw = '美剧'

data = {
    'kw': kw,
    'ie': 'utf-8',
    'pn': '100'
}

data_url = up.urlencode(
    data
)
# 编码
print(data_url)
# 解码
ret = up.unquote(data_url)
print(ret)

request = ur.Request('https://tieba.baidu.com/f?' + data_url)
response = ur.urlopen(request).read()
with open('%s.html' % kw, 'wb') as f:
    f.write(response)